//
//  OriginalView.swift
//  Weibo项目
//
//  Created by vn on 16/7/23.
//  Copyright © 2016年 vn. All rights reserved.
//

import UIKit
import SDWebImage
class OriginalView: UIView {
    
    
    var StatusModel:StatusViewModel?{
        
        
        //给控件赋值
        didSet{
            
            
            //设置文字字体
            name_lb.text = StatusModel?.homeModel?.user?.name
            
            //设置用户头像
        let url = StatusModel?.homeModel?.user?.profile_image_url
        headeImageView.sd_setImageWithURL(NSURL(string: url ?? ""), placeholderImage: UIImage(named:"avatar_default"))
          
           //设置会员等级
            memberImageView.image = StatusModel?.memberImage
            
            //设置认证
            
            avatarImageView.image = StatusModel?.avatarImage
        
            //微博来源
             source_lb.text = StatusModel?.homeModel?.source
            
            
             
            //测试数据
            time_lb.text = "三分钟"
            
                content_lb.text = "无敌是多磨寂寞,无敌是多磨寂寞无敌是多磨寂寞无敌是多磨寂寞无敌是多磨寂寞无敌是多磨寂寞无敌是多磨寂寞无敌是多磨寂寞无敌是多磨寂寞无"            
            
            
            
            
            
            
        }
        
        
        
        
        
        
        
        
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        
         setUpUI()
        
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    //添加控件
    func setUpUI(){
        
        addSubview(headeImageView)
        addSubview(name_lb)
        addSubview(memberImageView)
        addSubview(time_lb)
        addSubview(source_lb)
        addSubview(avatarImageView)
        addSubview(content_lb)
      //设置约束,头像
        headeImageView.snp_makeConstraints { (make) -> Void in
            
            make.top.leading.equalTo(self).offset(10)
            make.width.height.equalTo(35)
            
            
        }
        
    
       //名字
        name_lb.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(headeImageView)
            make.leading.equalTo(headeImageView.snp_trailing).offset(10)
            
            
        }
        
        
        //会员等级
          memberImageView.snp_updateConstraints { (make) -> Void in
            
            make.centerY.equalTo(name_lb.snp_centerY)
            make.leading.equalTo(name_lb.snp_trailing).offset(10)
            
            
        }
        
        
        //时间
        time_lb.snp_makeConstraints { (make) -> Void in
            
            make.bottom.equalTo(headeImageView)
            make.leading.equalTo(name_lb)
            
            
        }
        
        
        //来源
        source_lb.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(time_lb)
            make.leading.equalTo(time_lb.snp_trailing).offset(10)
            
            
        }
        
       //认证
        
        avatarImageView.snp_makeConstraints { (make) -> Void in
            
            make.centerY.equalTo(headeImageView.snp_bottom)
            make.centerX.equalTo(headeImageView.snp_trailing)
            
            
        }
        
        //内容
        
        content_lb.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(self).offset(10)
            make.top.equalTo(headeImageView.snp_bottom).offset(10)
            
            
            
            
        }
        
        //原创微博约束
        self.snp_makeConstraints { (make) -> Void in
            
            make.bottom.equalTo(content_lb).offset(10)
            
            
            
            
        }
        
        
    }
    
    
    
    //用户头像
    private lazy var headeImageView:UIImageView = {
       
        let view = UIImageView()
        
        view.image = UIImage(named:"avatar_default")
        
        return view
        
    }()
    
    //用户名称
    private lazy var name_lb:UILabel = {
        
        let lb = UILabel()
        
        lb.textColor = UIColor.blackColor()
        lb.font = UIFont.systemFontOfSize(15)
        
         return lb
        
    }()
    
    
    //微博等级
    
    private lazy var memberImageView:UIImageView = {
        
        let imageView = UIImageView()
        
        return imageView
        
    }()
    
    
    //时间Lable
    
    private lazy var time_lb:UILabel = {
        
        let lb = UILabel()
        
        lb.textColor = UIColor.redColor()
        lb.font = UIFont.systemFontOfSize(10)
        
        
       return lb
    }()
    
    
    //来源
    
    private lazy var source_lb:UILabel = {
        
        let lb = UILabel()
        lb.textColor = UIColor.grayColor()
        lb.font = UIFont.systemFontOfSize(10)
        
        
       
        return lb
        
    }()
    
    
    //认证
    private lazy var avatarImageView:UIImageView = {
       let avat = UIImageView()
        
        avat.image = UIImage(named:"avatar_vgirl")
        
         return avat
    }()
    
    
    //内容
    private lazy var content_lb:UILabel = {
        
      let lb = UILabel()
        
       lb.preferredMaxLayoutWidth = SCREENW - 20
        lb.numberOfLines = 0
        
        return lb
        
    }()
    
    
    
}
